#include "LightScript.hpp"
#include <Utility/StringTools.hpp>

namespace zzz{
bool Script<Light>::LoadFromMemory( istringstream &iss, Light &l, const string &path )
{
  string tmp;
  while(true)
  {
    iss>>tmp;
    if (iss.fail()) break;
    ToLow(tmp);
    if (tmp=="p" || tmp=="pos" || tmp=="position" || tmp=="pst")
    {
      iss>>l.m_pos[0]>>l.m_pos[1]>>l.m_pos[2]>>l.m_pos[3];
      memcpy(l.m_oripos,l.m_pos,sizeof(float)*4);
    }
    else if (tmp=="a" || tmp=="amb" || tmp=="ambient" || tmp=="abt")
    {
      iss>>l.m_amb[0]>>l.m_amb[1]>>l.m_amb[2]>>l.m_amb[3];
    }
    else if (tmp=="d" || tmp=="dif" || tmp=="diffuse" || tmp=="dfs")
    {
      iss>>l.m_dif[0]>>l.m_dif[1]>>l.m_dif[2]>>l.m_dif[3];
    }
    else if (tmp=="s" || tmp=="spe" || tmp=="specular" || tmp=="spc")
    {
      iss>>l.m_spe[0]>>l.m_spe[1]>>l.m_spe[2]>>l.m_spe[3];
    }
    else if (tmp=="l" || tmp=="lig" || tmp=="light" || tmp=="lit")
    {
      int x;
      iss>>x;
      if (x==0) l.m_mylight=GL_LIGHT0;
      else if (x==1) l.m_mylight=GL_LIGHT1;
      else if (x==2) l.m_mylight=GL_LIGHT2;
      else if (x==3) l.m_mylight=GL_LIGHT3;
      else if (x==4) l.m_mylight=GL_LIGHT4;
      else if (x==5) l.m_mylight=GL_LIGHT5;
      else if (x==6) l.m_mylight=GL_LIGHT6;
      else if (x==7) l.m_mylight=GL_LIGHT7;
    }
    else
    {
      printf("UNKNOWN PARAMETER: %s\n",tmp.c_str());
      return false;
    }
  }
  l.m_inited=true;
  return true;

}
}